package com.itheima;

import com.sun.jdi.BooleanValue;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.function.BiConsumer;

/**
 * @ProjectName: ybxy6
 * @Titile: MapDemo
 * @Author: 86183
 * @Description: TODO
 */
public class MapDemo {
    public static void main(String[] args) {
        test1();
        test2();
        test3();
    }
    public static void test1(){
    Map<String,Double> map=new HashMap<>();
    map.put("张三", 100.0);
    map.put("李四", 200.0);
    map.put("王五", 300.0);
    map.put("赵六",400.0);

    Set<String> keySet = map.keySet();
for(String key:keySet){
    Double value = map.get(key);
    System.out.println(key+"------"+value);
}
    }
    public static void test3() {
        Map<String, Double> map = new HashMap<>();
        map.put("张三",100.0);
        map.put("李四", 200.0);
        map.put("王五",300.0);
        map.put("赵六", 400.0);
    /*map.forEach(new BiConsumer<String, Double>() {
        @Override
        public void accept(String key, Double aDouble) {
            System.out.println(key+"------"+aDouble);
        }
    });*/
    map.forEach((key,value)->{System.out.println(key+"------"+value);
    });
    }
    public static void test2() {
        Map<String, Double> map = new HashMap<>();
        map.put("张三",100.0);
        map.put("李四", 200.0);
        map.put("王五",300.0);
        map.put("赵六", 400.0);
       //1.将map集合转换为Set集合，将map中的key-value对封装为Entry对象，并添加到Set集合中
        Set<Map.Entry<String, Double>> entrySet = map.entrySet();
        //2.遍历Set集合，取出Entry对象，再从Entry对象中取出key和value
        for(Map.Entry<String, Double> entry:entrySet){
            //3.再通过Entry对象获取key和value
            String key = entry.getKey();
            Double value = entry.getValue();
            System.out.println(key+"------"+value);
        }
    }

     private static void test1(String[] args) {
        Map<String, Double> map = new HashMap<>();
        map.put("张三",100.0);
        map.put("李四", 200.0);
        map.put("王五",300.0);
        map.put("赵六", 400.0);
        map.put("田七", 77.9);
        map.put("田七", 77.9);
        System.out.println(map);
        map.remove("田七");
        System.out.println(map);
        //map.clear();
        //System.out.println(map);
boolean b1=map.containsKey("李四");
System.out.println(b1);
boolean b2=map.containsValue(77.9);
System.out.println("b2="+b2);

boolean empty = map.isEmpty();
System.out.println("empty="+empty);
int size = map.size();
System.out.println("size="+size);
    }
}

